package com.springcloud.play.novel.task;

import com.springcloud.play.novel.service.NovelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
public class NovelCrawlTask {

    @Autowired
    private NovelService novelService;
    
    /**
     * 定时爬取小说更新
     * 配置在NovelCrawlerConfig中的cron表达式控制执行时间
     */
    @Scheduled(cron = "${novel.crawler.cronExpression:0 0 2 * * ?}")
    public void scheduledCrawlNovels() {
        System.out.println("定时任务开始执行小说爬取更新...");
        try {
            novelService.scheduledCrawl();
            System.out.println("定时任务完成小说爬取更新");
        } catch (Exception e) {
            System.err.println("定时任务执行小说爬取更新失败: " + e.getMessage());
            e.printStackTrace();
        }
    }
}